<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page import="java.sql.*"%> 
<%

request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";


String url="jdbc:mysql://sqld.duapp.com:4050/ToszmXBSdefwbBRfZIAt";
String user="Ec2chH8MHnfQo9cUi0ga6jw9";
String password="tP94jTsaYQCj8XkRw8nb3QmmYAFp4OX0";


//String url="jdbc:mysql://312224.cicp.net:38833/test?useUnicode=true&amp;characterEncoding=utf-8";
//String user="root";
//String password="niufoxyyn123.";


//String url="jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=utf-8";
//String user="root";
//String password="niuxiao";


Class.forName("com.mysql.jdbc.Driver");
//获得Connection对象
Connection DBConn = DriverManager.getConnection(url,user,password);
PreparedStatement ps=null;

Integer pageSize = 8;
String pageInt = request.getParameter("pageInt")==null?"1":request.getParameter("pageInt");
//Integer limitStr = pageSize*(Integer.parseInt(pageInt)-1);
//Integer limitEnd = pageSize*(Integer.parseInt(pageInt));
//Integer totalPage = 0;
//String sql = "select * from reservoir t limit "+limitStr+","+limitEnd;
String name = request.getParameter("name")==null?"":request.getParameter("name").trim();
//name=new String(name.getBytes("ISO8859-1"),"utf-8").trim();
name=java.net.URLDecoder.decode(new String(name), "utf-8");;
String town = request.getParameter("town")==null?"":request.getParameter("town").trim();
town=java.net.URLDecoder.decode(new String(town), "utf-8");
String sql = "select id,name,town from reservoir t where 1=1";
ResultSet rs = null;
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta name="viewport" content="width=device-width,initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
<html>
  <head>
    <base href="<%=basePath%>">
    <title>水库查询</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
	<link rel="stylesheet" href="css/easyui.css" type="text/css"></link>
	<link rel="stylesheet" href="css/table.css" type="text/css"></link>
	<style>
	
	</style>
	<script>
	

	function sumbit(){
	    var name=document.getElementById("name").value;
	    var town=document.getElementById("town").value;
		document.getElementById("reserSerch").action="reser.jsp?town="+encodeURI(encodeURI(town))+"&name="+encodeURI(encodeURI(name));
		document.getElementById('reserSerch').submit();
	}
	function turnPage(id){
		window.location.href="reserInfo.jsp?id="+id;
	}
	function resetbutton(){
		$("#reserSerch input").val("");
		document.getElementById("town").value="";
		sumbit();
	}
	
	$(function(){
	var town = '<%=town%>' ;
	var select =  document.getElementById("town");
	if(town!=''){
		var varItem = new Option(town,town);
		select.options.add(varItem) ;
	}
	$.getJSON('json/townCode_date.json', function(data) {
	      $(data).each(function(i,ite){ 
	      		var varItem = new Option(ite.text,ite.id);
	      		select.options.add(varItem) 
	      })
        });
	}) 
	
	function onsu(){
	
	}
	
	</script>
 </head>
  <body >
  <form id="reserSerch">
  <div id="menubox">
  	<ul>
		<li>水库山塘信息查询</li>
 		<li>所属乡镇：
	<select id="town" name="town" onchange ="sumbit();" >
	</select></li>
    	<li>水库名称：<input type="text" id="name" name="name" value="<%=name %>"></input> </li>
  		<li><button onclick = "sumbit();">搜索</button>
  		<button onclick = "resetbutton();">清空</button></li>
  	</ul>
  </div>
  
 <div id="menubox1">
 <ul>
    <%
try {
	int i=0;
	int j=1;
		if(name!=null && name!= ""&&!name.equals("null") && !name.equals("")){
			sql=sql+" and name like ?";
			i++;
		}
		if(town!=null && town!= ""&&!town.equals("null") && !town.equals("")){
			sql=sql+" and town like ?";
			i++;
		}
		sql+=" order by totleCapacity desc,town";
			ps = DBConn.prepareStatement(sql);
		if(name!=null && name!= ""&&!name.equals("null") && !name.equals("")){
			ps.setString(j, "%"+name+"%");
		}
		if(town!=null && town!= ""&&!town.equals("null") && !town.equals("")){
			ps.setString(i, "%"+town+"%");
		}
			System.out.print(sql);
			rs = ps.executeQuery();
			while(rs.next()){
%>
  <li onclick="turnPage('<%= rs.getString("id")%>');">
	  <font>
	  <a class="le"><%=rs.getString("name") %></a>
	  <a class="ri"><%=rs.getString("town") %></a>
	  </font>
  </li>
<%
	}	
} catch (SQLException e) {
	e.printStackTrace();
}finally {
	DBConn.close();
}
%>
</ul>
</div>
</form>
  </body>
</html>
